package com.hrzyit.whistle.cases.ui.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.hrzyit.whistle.cases.R
import com.hrzyit.whistle.cases.data.bean.CaseIndexDeptInfoVo
import kotlinx.android.synthetic.main.item_index_select_dept.view.*
import kotlinx.android.synthetic.main.item_select_dept.view.*
import kotlinx.android.synthetic.main.item_select_dept.view.mDepartmentNameTv
import kotlinx.android.synthetic.main.item_whistle_dept.view.*
import me.yokeyword.indexablerv.IndexableAdapter

/**
 * 单位索引选择器适配器，只对单位选项栏和选项头进行操作
 * @author YangWei
 * @date 2019/3/29
 */
class IndexDeptOnlySelectAdapter(context: Context) : IndexableAdapter<CaseIndexDeptInfoVo>() {

    private var mInflater: LayoutInflater = LayoutInflater.from(context)


    override fun onCreateTitleViewHolder(parent: ViewGroup?): RecyclerView.ViewHolder {
        val view = mInflater.inflate(R.layout.item_index_whistle_dept, parent, false)
        return IndexVH(view)
    }

    override fun onCreateContentViewHolder(parent: ViewGroup?): RecyclerView.ViewHolder {
        val view = mInflater.inflate(R.layout.item_whistle_dept, parent, false)
        return ContentVH(view)
    }

    // 绑定行数据
    override fun onBindContentViewHolder(holder: RecyclerView.ViewHolder?, entity: CaseIndexDeptInfoVo?) {
        var vh = holder as ContentVH
        vh.mDepartmentNameTv.text = entity?.simpleName
        entity?.let {
            var userCount = 0
            it.caseIndexUserInfoVoList?.let { item ->
                userCount = item.size
            }

            when (userCount > 0) {
                true -> {
                    vh.mSelectUserCountTv.visibility = View.VISIBLE
                    vh.mSelectUserCountTv.text = "$userCount"

                }
                else -> {
                    vh.mSelectUserCountTv.visibility = View.GONE

                }
            }
        }
    }

    // 绑定索引数据
    override fun onBindTitleViewHolder(holder: RecyclerView.ViewHolder?, indexTitle: String?) {
        var vh = holder as IndexVH
        vh.mIndexTv.text = indexTitle
    }

    private class IndexVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var mIndexTv: TextView = itemView.mIndexTv as TextView

    }

    private class ContentVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var mDepartmentNameTv: TextView = itemView.mDepartmentNameTv as TextView
        var mSelectUserCountTv: TextView = itemView.mSelectUserCountTv as TextView
    }

}